/**
 * 
 */
package org.statewalker.parser.wiki.tokenizer.inline;

import org.statewalker.parser.wiki.grammar.WikiInlineDict;
import org.statewalker.tokenizer.AbstractTokenizer;
import org.statewalker.tokenizer.CharStream;
import org.statewalker.tokenizer.StreamToken;
import org.statewalker.tokenizer.CharStream.Marker;

public class LinkTokenizer extends AbstractTokenizer {

    public LinkTokenizer() {
        this(WikiInlineDict.A);
    }

    public LinkTokenizer(String key) {
        super(key);
    }

    public StreamToken read(CharStream stream) {
        StreamToken result = null;
        Marker marker = stream.markPosition();
        try {
            char ch = stream.getChar();
            if (ch == '[') {
                while (ch != 0 && ch != ']') {
                    stream.incPos();
                    ch = stream.getChar();
                }
                if (ch == ']') {
                    stream.incPos();
                    result = newToken(stream, marker);
                }
            }
            return result;
        } finally {
            marker.close(result == null);
        }
    }
}